//
//  TeamManager.m
//  SSC
//
//  Created by 红沙尘 on 17/6/26.
//  Copyright © 2017年 红沙尘. All rights reserved.
//

#import "TeamManager.h"
#import "TeamManagerCell.h"

@interface TeamManager ()

@end

@implementation TeamManager

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    return [super initWithNibName:NSStringFromClass([self.superclass class]) bundle:nibBundleOrNil];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setTitle:@"团队管理"];
}

#pragma mark - 网络数据

- (void)loadData{
    [super loadData];
    WeakSelf
    
    __weak UITableView *weakTableView = mainTableView;
    
    [SSCRequest agentDayinfoListStartdt:[MTool formartDate:startField.text]
                                  enddt:[MTool formartDate:endField.text]
                                   page:page
                                success:^(NSDictionary *responseObject)
     {
         [weakTableView.mj_header endRefreshing];
         [weakTableView.mj_footer endRefreshing];
         [weakSelf loadWithArray:[NSString safeArray:responseObject[@"data"]]];
     } fail:^(NSError *error) {
         [weakTableView.mj_header endRefreshing];
         [weakTableView.mj_footer endRefreshing];
     }];
    
    [SSCRequest sumAgentListSuccess:^(NSDictionary *responseObject) {
        
        NSDictionary *data = responseObject[@"data"];
        
        UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 0)];
        
        UILabel *labelA = [self labelWithText:[NSString stringWithFormat:@"投注汇总:%@",data[@"orderamount"]]
                                       inView:headView
                                            y:0];
        UILabel *labelB = [self labelWithText:[NSString stringWithFormat:@"充值汇总:%@",data[@"rechamount"]]
                                       inView:headView
                                            y:labelA.bottom];
        UILabel *labelC = [self labelWithText:[NSString stringWithFormat:@"返点汇总:%@",data[@"rateamount"]]
                                       inView:headView
                                            y:labelB.bottom];
        headView.height = labelC.bottom;
        
        weakTableView.tableHeaderView = headView;
        
        [self noLabel].hidden = YES;
        
    } fail:^(NSError *error) {
        [self noLabel].hidden = YES;
    }];
}

- (void)loadWithArray:(NSArray *)array {
    
    [super loadWithArray:array];
    
    if (mainTableView.tableHeaderView) {
        [self noLabel].hidden = YES;
    }
}

#pragma mark - IBAction

#pragma mark - table

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return dataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    TeamManagerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TeamManagerCell"];
    
    [cell loadWithDict:dataArray[indexPath.row]];
    
    return cell;
}

- (void)setupUI {
    [super setupUI];

    mainTableView.rowHeight = 173;
    mainTableView.estimatedRowHeight = 173;
    [mainTableView registerNib:[UINib nibWithNibName:@"TeamManagerCell" bundle:nil]
        forCellReuseIdentifier:@"TeamManagerCell"];
}

- (UILabel *)labelWithText:(NSString *)text inView:(UIView *)view y:(CGFloat)y{
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(15, y, ScreenWidth, 30)];
    label.textColor = [UIColor colorWithHexString:@"#333333"];
    label.font = [MTool fontOfSize:14];
    label.text = text;
    [view addSubview:label];
    return label;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
